import { defineStore } from "pinia"

export const useCommonStore = defineStore({
    id: 'common',
    state: () => {
        return { 
            tabbarActive: 'index',
            user_info: {
                id: 0,
                user_no: '',
                phone: '',
                nick_name: '',
                real_name: '',
                signature: '',
                intro: '',
                age: 0,
                avatar: '',
                constellation: '',
                gender: 1,
                school: '',
                birthday: '',
                province: '',
                city: '',
                qq: '',
                email: '',
                state: '',
                remark: '',
                last_login: '',
                created_at: '',
                updated_at: '',
                deleted_at: '',
            } 
        }
    },
    getters: {
        // fullName: (state) => {
        //   return state.tabbarActive
        // },
    },
    actions: {
        updateTabbarActive(tabbarActive: string): void {
            this.tabbarActive = tabbarActive
        }, 
        updateUserInfo(userInfo: STORE.UserInfo): void {
            this.user_info = userInfo
        }
    },
    // 开启数据缓存
    persist: {
        enabled: true,
        strategies: [
            {
              key: 'common_key',
              paths: ['tabbarActive', 'user_info'],
              storage: localStorage, // 默认 sessionStorage 
            }
          ]
    }
})
